
active="DEV"
active_lower="DEV"

log_names=(
spray
)

service_names=(
spray

)

service_index=""
http="http"

if [ ! -n "$1" ]; then
	echo "请输入http地址或服务名"
	exit
elif [[ $1 == *$http* ]]; then
    for index in `seq 0 $((${#service_names[*]}-1))`
	do
		service_name=${service_names[$index]}
		if [[ $1 == *$service_name* ]]; then
			# remove the old jar file
			echo "rm -f $service_name*.jar"
			rm -f $service_name*.jar
			# download a new jar file
			echo "wget $1"
			wget $1
			# kill the old service
			ps -ef | grep $service_name | grep .jar | awk '{print $2}' | while read pid
			do
			echo "kill -9 $pid"
			kill -9 $pid
			done
			# start a new service   
			service_short_path=$service_name
			echo "nohup java -Xmx2g -Dspring.profiles.active=$active_lower -jar $service_name*.jar --spring.config.location=/home/deploy/$active/config/$service_short_path/ &"
			nohup java -Xmx2g -Dspring.profiles.active=$active_lower -jar $service_name*.jar --spring.config.location=/home/deploy/$active/config/$service_short_path/ &      
			service_index=$index 
			break
		fi
	done
	echo "tail -100f ./log/${log_names[$service_index]}*.log"
	tail -100f ./log/${log_names[$service_index]}*.log
else		
	for index in `seq 0 $((${#service_names[*]}-1))`
	do
		service_name=${service_names[$index]}
		if [[ $1 == *$service_name* ]]; then								
			# kill the old service
			ps -ef | grep $service_name | grep .jar | awk '{print $2}' | while read pid
			do
			echo "kill -9 $pid"
			kill -9 $pid
			done
			# start a new service   
			service_short_path=$service_name
			echo "nohup java -Xmx2g -Dspring.profiles.active=$active_lower -jar $service_name*.jar --spring.config.location=/home/deploy/$active/config/$service_short_path/ &"
			nohup java -Xmx2g -Dspring.profiles.active=$active_lower -jar $service_name*.jar --spring.config.location=/home/deploy/$active/config/$service_short_path/ &      
			service_index=$index 
			break
		fi
	done
	echo "tail -100f ./log/${log_names[$service_index]}*.log"
	tail -100f ./log/${log_names[$service_index]}*.log
fi
